package com.xinzhi.controller;


import com.xinzhi.model.Result;
import com.xinzhi.model.User;
import com.xinzhi.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
public class UserController {


    @Autowired
    private UserService userService;
    @RequestMapping("/queryUsers")
    @ResponseBody
    public Result queryUserByCondition(User user){
        List<User> users = userService.queryUserByCondition(user);
        if (users.size()!=0){
            return Result.ok(users);
        }
        return Result.error(666,"没有符合条件的数据");
    }

    @RequestMapping("/updateUser")
    @ResponseBody
    public Result updateUser(User user){
        int i = userService.updateUser(user);
        if (i>0){
            return Result.ok("修改成功");
        }
    return Result.error(666,"修改失败");
    }




    @RequestMapping("/queryUsersByIds")
    @ResponseBody
    public Result  queryUsersByIds(@RequestParam("ids") List<Integer> ids){
        List<User> users = userService.queryUsersByIds(ids);
        if (users!=null){
            return Result.ok(users);
        }
       return Result.error(666,"没有符合条件的数据");
    }


}
